#ifndef __TERRAIN_INTERFACE_HEADER__
#define __TERRAIN_INTERFACE_HEADER__



class Terrain
{
	struct Vertex
	{
		float x, z;
	};

	enum LODFlags
	{
		LOD_FLAG_NONE		= 0x00000000,
		LOD_FLAG_TOP		= 0x00000001,
		LOD_FLAG_BOTTOM		= 0x00000002,
		LOD_FLAG_LEFT		= 0x00000004,
		LOD_FLAG_RIGHT		= 0x00000008,
		LOD_FLAG_ALL		= 0x0000000F,
		LOD_FLAG_FORCE_32	= 0x7fffffff
	};

	struct PatchParameters
	{
		float	pos_x, pos_z;
		float	scale;
		float	dummy;
	};

private:
	GraphicDeviceD3D11*					m_pGraphicDevice;

	VertexBufferD3D11*					m_pVertexBuffer;
	uint32								m_uiVertexCount;

	IndexBufferD3D11*					m_pIndexBuffer;
	uint32								m_uiIndexCount;
	
	// Immutable State Objects
	D3D11_BLEND_DESC					m_descBlendState;
	ID3D11BlendState*					m_pd3dBlendState;

	D3D11_DEPTH_STENCIL_DESC			m_descDepthStencilState;
	ID3D11DepthStencilState*			m_pd3dDepthStencilState;

	D3D11_RASTERIZER_DESC				m_descRasterizer;
	ID3D11RasterizerState*				m_pd3dRasterizerState;

	// Shaders
	ID3D11InputLayout*					m_pd3dInputLayout;
	ID3D11VertexShader*					m_pd3dVertexShader;
	ID3D11PixelShader*					m_pd3dPixelShader;
	ID3D11GeometryShader*				m_pd3dGeometryShader;

	// Constant Buffer
	typedef vector<vector<ConstantBuffer<PatchParameters>*>> Patches;
	Patches								m_arrPatchesCB;

	uint32								m_uiTerrainSize;

	// Textures
	TextureD3D11*						m_pTextureHeightMap;
	TextureD3D11*						m_pTextureIndexMap;
	TextureD3D11*						m_pTextureArrayMaterials;


private:

	void CreateSharedVertexBuffer(uint32 uiVertexSideCount);
	bool CreateIndexBuffer(uint16 uiPatchBlockCount);

	bool CreateImmutableStateObjects();
	bool CreateShaders();
	bool LoadTextures();
public:
	Terrain();
	~Terrain();

	bool Initialize(GraphicDeviceD3D11* pDevice, const string& fileName, uint32 uiPatchSize);
	void Finalize();

	void Render();

};


#endif
